package sc.prototype.pfs.eventnotify.collector.impl;

import java.util.HashMap;

import javax.annotation.PostConstruct;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import sc.prototype.pfs.eventnotify.collector.ContentCollector;
import sc.prototype.pfs.eventnotify.collector.ContentCollectorFactory;
import sc.prototype.pfs.eventnotify.model.NotifyConfig;
import sc.prototype.pfs.eventnotify.model.NotifyContext;
import sc.prototype.pfs.eventnotify.model.enums.ContentCollectorType;

public class DefaultContentCollectorFactory implements ContentCollectorFactory {

    Logger logger = LoggerFactory.getLogger(this.getClass());

    HashMap<ContentCollectorType, ContentCollector> collectorMap;

    @PostConstruct
    public void init() {
        logger.info("通知内容采集器字典初始化完毕：{}", collectorMap);
    }

    @Override
    public ContentCollector create(NotifyConfig config, NotifyContext context) {
        ContentCollectorType type = config.getContentCollectorType();
        ContentCollector collector = collectorMap.get(type);
        if (collector != null) {
            return collector;
        } else {
            String err = String.format("未注册的采集器类型：%s，%s", type, config);
            throw new IllegalArgumentException(err);
        }
    }

    public void setCollectorMap(HashMap<ContentCollectorType, ContentCollector> collectorMap) {
        this.collectorMap = collectorMap;
    }

}
